package com.ylkj.patient.moduleimpl;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.interfaceapi.MineApi;
import com.example.messagemodule.utils.MessageUtils;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.yljk.live.common.utils.MediaCountyManager;
import com.examination.mlib.interfaceapi.MineBackApi;
import com.ylkj.patient.MyActivityManager;
import com.ylkj.patient.newpickview.PickViewUtils;
import com.ylkj.patient.pickview.PickerView;
import com.ylkj.patient.ui.activities.MainActivity;
import com.ylkj.patient.utils.AppReactUtils;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;

@Route(path = ARouterConstants.MineModuleImpl)
public class MineModuleImpl implements MineBackApi {

    /**
     * 无参android to rn
     * @param context
     * @param pluginId rn包名
     * @param componentName rn页面名
     */
    @Override
    public void Android2RnPush(Context context, String pluginId, String componentName) {
        AppReactUtils.INSTANCE.push(context,pluginId,componentName);
    }

    /**
     * 带参androi to rn
     * @param context
     * @param pluginId rn包名
     * @param componentName rn页面名
     * @param bundle 参数
     */
    @Override
    public void Android2RnPush(Context context, String pluginId, String componentName, Bundle bundle) {
        AppReactUtils.INSTANCE.push(context,pluginId,componentName,bundle);
    }

    @Override
    public boolean logoutIM() {
        return MessageUtils.logoutIM();
    }

    @Override
    public void init(Context context) {

    }

    @Override
    public void logoutLive(){
        MediaCountyManager.getInstance().appLogout();
    }

    @Override
    public void openPickView(HashMap<String,Object> map, Activity activity, MineApi mineApi) {
        PickerView.getInstance(MyActivityManager.getInstance().getCurrentActivity()).getPicker(map, MyActivityManager.getInstance().getCurrentActivity(), new Promise() {
            @Override
            public void resolve(Object value) {
                mineApi.onSuccess((String) value);
            }

            @Override
            public void reject(String code, String message) {

            }

            @Override
            public void reject(String code, Throwable throwable) {

            }

            @Override
            public void reject(String code, String message, Throwable throwable) {

            }

            @Override
            public void reject(Throwable throwable) {

            }

            @Override
            public void reject(Throwable throwable, WritableMap userInfo) {

            }

            @Override
            public void reject(String code, @NonNull @NotNull WritableMap userInfo) {

            }

            @Override
            public void reject(String code, Throwable throwable, WritableMap userInfo) {

            }

            @Override
            public void reject(String code, String message, @NonNull @NotNull WritableMap userInfo) {

            }

            @Override
            public void reject(String code, String message, Throwable throwable, WritableMap userInfo) {

            }

            @Override
            public void reject(String message) {

            }
        });
    }

    @Override
    public void hideImLayout(Activity activity) {
        if (activity != null && activity instanceof MainActivity){
            ((MainActivity)activity).hideImLayout();
        }
    }

    @Override
    public void showImLayout(Activity activity) {
        if (activity != null && activity instanceof MainActivity){
            ((MainActivity)activity).showImLayout();
        }
    }

}
